package com.radiant.data.entity;

import java.util.List;

import org.apache.commons.beanutils.ConvertUtilsBean;

import com.google.inject.Inject;
import com.radiant.data.entity.converter.SimpleDBEntityConverter;

public class UserDAOImpl extends SimpleDBDAO<User> implements UserDAO {

	@Inject
	private ProfileDAO profileDAO;
	
	@Inject
	private UserDAO userDAO;

	@Inject
	private ChildDAO childDAO;

	public UserDAOImpl() {
		super(User.class);
	}


	public User findByUserName(String userName) {
		StringBuffer whereClause = new StringBuffer();
		whereClause.append("userName = ").append("'").append(userName).append("'");
		List<User> users;
		users = query(whereClause.toString(), null, 0, true);
		if (!users.isEmpty()) {
			return users.get(0);
		} else {
			return null;
		}
	}


	@Override
	protected void registerConverters(ConvertUtilsBean convertUtilsBean) {
		convertUtilsBean.register(new SimpleDBEntityConverter<ProfileDAO>(preProcessor, profileDAO), Profile.class);
		convertUtilsBean.register(new SimpleDBEntityConverter<UserDAO>(preProcessor, userDAO), User.class);		
		convertUtilsBean.register(new SimpleDBEntityConverter<ChildDAO>(preProcessor, childDAO), Child.class);		
	}
}
